﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.AnalysisServices.AdomdClient;
using System.Data;

namespace RetailAnalytic.Tools.MDXTemplate
{
    public static class TemplateService
    {
        public static List<string> GetSchemaMeasures(AdomdConnection conn, string dataMember)
        {
            List<string> measures = new List<string>();
            DataTable dt;
            string[] restr = new string[] { null, null, dataMember };
            dt = conn.GetSchemaDataSet(AdomdSchemaGuid.Measures, restr).Tables[0];
            if (!(dt == null))
            {
                DataRow l_RowD;
                foreach (DataRow tempLoopVar_l_RowD in dt.Rows)
                {
                    l_RowD = tempLoopVar_l_RowD;
                    measures.Add(l_RowD["MEASURE_CAPTION"].ToString());
                }
            }
            measures.Sort();
            return measures;
        }

        public static List<string> GetSchemaDimensions(AdomdConnection conn, string dataMember)
        {
            List<string> dimensions = new List<string>();
            DataTable dtDim;
            string[] restr = new string[] { null, null, dataMember };
            dtDim = conn.GetSchemaDataSet(AdomdSchemaGuid.Dimensions, restr).Tables[0];
            foreach (DataRow tempLoopVar_l_RowD in dtDim.Rows)
            {
                if (tempLoopVar_l_RowD["DIMENSION_CAPTION"].ToString() != "Measures")
                {
                    dimensions.Add(tempLoopVar_l_RowD["DIMENSION_CAPTION"].ToString());
                }
            }
            return dimensions;
        }
    }
}
